package zl.io;
import java.io.PipedOutputStream;
import java.io.PipedInputStream;
import java.io.IOException;

//管道输出
class Send implements Runnable
{
	private PipedOutputStream out;

	public Send()
	{
		this.out = new PipedOutputStream();
	}

	public PipedOutputStream getPipedOutputStream()
	{
		return this.out;
	}

	public void run()
	{
		String str = "zhangle";
		try
		{
			out.write(str.getBytes());
			out.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}

//管道输入
class Receive implements Runnable 
{
	private PipedInputStream in;

	public Receive()
	{
		this.in = new PipedInputStream();
	}

	public PipedInputStream getPipedInputStream()
	{
		return this.in;
	}

	public void run()
	{
		byte[] b = new byte[1024];
		int temp = 0;
		try
		{
			temp = in.read(b);
			in.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		System.out.println(new String(b,0,temp));
	}
}

public class IODemo06
{
	public static void main(String[] args)
	{
		Send s = new Send();
		Receive r = new Receive();
		try
		{
			s.getPipedOutputStream().connect(r.getPipedInputStream());
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		new Thread(s).start();
		new Thread(r).start();
	}
}